package com.x.control;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.x.service.transactional.ShipmentsService;

@Controller
@RequestMapping("/shipments")
public class ShipmentsController {
	@Autowired(required = true)
	ShipmentsService shipmentsService;

	@RequestMapping(value = "/upload")
	public ModelAndView uploadShipments(
			@RequestParam(value = "file", required = false) MultipartFile file,
			HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("home");
		mv.addObject("nav", "configuration");
		if (shipmentsService.upload(file)) {
			mv.addObject("error",
					"create basic configuration fail: Duplicate Configs!");
		}
		return mv;
	}
}
